<template>
  <div>
    <el-table v-loading="loading" :data="registerLeaveList" @selection-change="handleSelectionChange">
      <el-table-column label="进修科目" align="center" prop="registerDeptName" />
      <el-table-column label="姓名" align="center" prop="userName" />
      <el-table-column label="工号" align="center" prop="jobNumber" width="170" />
      <el-table-column label="请假状态" align="center" prop="leaveStatus">
        <template slot-scope="scope">
          {{ leaveStatusList[scope.row.leaveStatus - 1].name }}
        </template>
      </el-table-column>
      <el-table-column label="请假类型" align="center" prop="leaveType">
        <template slot-scope="scope">
          {{ leaveTypeList[scope.row.leaveType - 1].name }}
        </template>
      </el-table-column>
      <el-table-column label="请假开始时间" align="center" prop="leaveStartDate" />
      <el-table-column label="请假结束时间" align="center" prop="leaveEndDate" />
      <el-table-column label="请假时长" align="center" prop="leaveDuration">
        <template slot-scope="scope">
          {{ scope.row.leaveDuration }}天
        </template>
      </el-table-column>
      <el-table-column label="请假原因" align="center" prop="leaveCause" show-overflow-tooltip />
      <el-table-column label="请假条" align="center" prop="leavePicture">
        <template slot-scope="scope">
          <image-preview :src="baseURL + scope.row.leavePicture" width="50px" height="50px" />
        </template>
      </el-table-column>
      <el-table-column label="有效状态" align="center" prop="effectiveStatusName" />
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script>
import { consts } from '@/api/business/consts'
import { listRegisterLeave } from '@/api/business/registerLeave'

export default {
  name: 'registerLeaveList',
  data() {
    return {
      // 根路径
      baseURL: process.env.VUE_APP_BASE_API,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 请假记录表格数据
      registerLeaveList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        registerId: null,
        leaveStatus: null,
        leaveType: null,
        leaveStartDate: null,
        leaveEndDate: null,
        leaveDuration: null,
        leaveCause: null,
        leavePicture: null,
        effectiveStatus: null
      },
      leaveStatusList: consts.leaveStatusList,
      leaveTypeList: consts.leaveTypeList,
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询请假记录列表 */
    getList() {
      this.loading = true
      listRegisterLeave(this.queryParams).then(response => {
        this.registerLeaveList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    }
  }
}
</script>
